package barinadroid.game;

import org.andengine.entity.scene.background.Background;
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.TextMenuItem;

public class MainMenuScene extends MenuScene implements IOnMenuItemClickListener
{
	public static MainMenuScene instance;

	public static MainMenuScene getSharedInstance()
	{
		if(instance == null)
			instance = new MainMenuScene();
		return instance;
	}

	GameActivity gameActivity;
	final int MENU_START = 0, MENU_SETTINGS = 1;

	private MainMenuScene()
	{
		super(GameActivity.getSharedInstance().camera);
		gameActivity = GameActivity.getSharedInstance();
		setBackground(new Background(0, 0, 0));
		IMenuItem startButton = new TextMenuItem(MENU_START, gameActivity.font, gameActivity.getString(R.string.start), gameActivity.getVertexBufferObjectManager());
		startButton.setPosition(50 + startButton.getWidth() / 2, mCamera.getHeight() / 2 - startButton.getHeight() / 2);
		IMenuItem settingsButton = new TextMenuItem(MENU_SETTINGS, gameActivity.font, gameActivity.getString(R.string.settings), gameActivity.getVertexBufferObjectManager());
		settingsButton.setPosition(50 + settingsButton.getWidth() / 2, startButton.getHeight() + settingsButton.getHeight() / 2);
		addMenuItem(startButton);
		addMenuItem(settingsButton);
		setOnMenuItemClickListener(this);
	}

	@Override
	public boolean onMenuItemClicked(MenuScene arg0, IMenuItem arg1, float arg2, float arg3)
	{
		switch (arg1.getID())
		{
			case MENU_START:
				gameActivity.setCurrentScene(GameScene.getSharedInstance());
				return true;
			case MENU_SETTINGS:
				gameActivity.setCurrentScene(SettingsScene.getSharedInstace());
				SettingsScene.getSharedInstace().setCallerScene(this);
				return true;
			default:
				break;
		}
		return false;
	}
}